import 'package:flutter/material.dart';
import 'package:flutterapp/Base/methodChannel/MethodChannelManager.dart';
import 'package:flutterapp/Base/style/MyStyles.dart';
import 'package:flutterapp/utils/LoginManager.dart';
import 'package:url_launcher/url_launcher.dart';

class PageMain extends StatefulWidget {
  static const ROUTER_NAME = "PageMain";

  @override
  _PageMainState createState() => _PageMainState();
}

class _PageMainState extends State<PageMain> {
  static const str1 = "    请点击下方按钮进入纸嘟嘟回收代理/回收员专用app,并将此app加入电池白名单并保持后台运行。";
  static const str2 = "    若未下载纸嘟嘟代理商/回收员专用app,请登录纸嘟嘟官方网站进行下载，下载地址：";
  static const str3 = "http://zhidudu.chinawzhs.cn";

  @override
  Widget build(BuildContext context) {
    return Scaffold(
        appBar: AppBar(
          title: Text("已登录",style: MyTextStyle.WHITE_18,),
          actions: [
            PopupMenuButton(
              itemBuilder: (context) {
                return [
                  PopupMenuItem(
                    child: Text("查看回收员位置"),
                    value: 1,
                  ),
                  PopupMenuItem(
                    child: Text("退出登录"),
                    value: 0,
                  )
                ];
              },
              onSelected: (val) {
                print(val);
                switch (val) {
                  case 0:
                    LoginManager.logout();
                    break;
                  case 1:
                    MethodChannelManager.getInstance().invoke(MethodTypes.SHOW_MAP);
                    break;
                }
              },
            )
          ],
        ),
        body: Container(
          child: Column(
            children: [
              Text(
                str1,
                style: MyTextStyle.GREY3_18,
              ),
              SizedBox(
                height: 8,
              ),
              Text(str2, style: MyTextStyle.GREY3_18),
              SizedBox(
                height: 8,
              ),
              FlatButton(onPressed: (){
                launch(str3);
              }, child: Text(str3,style: TextStyle(fontSize: 16,color: Colors.lightBlue)),),
              Expanded(
                child: Text(""),
              ),
              Container(
                child: MaterialButton(
                  height: 42,
                  onPressed: () {
                    MethodChannelManager.getInstance().invoke(
                        MethodTypes.OPEN_APP_BY_PACKAGE_NAME,
                        {"packageName": "com.zhilaotou"});
                  },
                  child: Text(
                    "点击进入纸嘟嘟app",
                    style: MyTextStyle.WHITE_18,
                  ),
                  color: MyColors.PRIMARY_COLOR,
                ),
                width: double.infinity,
              )
            ],
          ),
          padding: EdgeInsets.all(10),
        ));
  }
}
